const fs = require('fs')
const path = require('path')

const { resolve } = require('source-map-resolve')

// 代码路径
const codeUrl = './dist/main.js'

// 加工（转换、编译、压缩、合并）后的代码
const code = fs.readFileSync(path.join(__dirname, codeUrl), 'utf-8')

// 解析过程按照 https://sourcemaps.info/spec.html
resolve(code, codeUrl, fs.readFile, (err, result) => {
  if (err) throw err
  console.log(result) // 得到解析后的结果
})


// const { SourceMapConsumer } = require('source-map')

// const rawSourceMap = JSON.parse(fs.readFileSync(path.join(__dirname, './dist/main.js.map'), 'utf-8'))

// console.log(rawSourceMap)
// SourceMapConsumer.with(rawSourceMap, null, consumer => {
//   console.log(consumer.originalPositionFor({ source: consumer.sources[0], line: 1, column: 1 }))
// })